package com.kantboot.user.account.web.controller;

import com.kantboot.global.rest.result.CommonSuccessStateCodeAndMsg;
import com.kantboot.user.account.domain.dto.UserAccountRegisterDTO;
import com.kantboot.user.account.domain.dto.UserAccountSendVerificationCodeDTO;
import com.kantboot.user.account.service.IUserAccountRegisterService;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户账号注册控制器
 */
@RestController
@RequestMapping("/user-account-web/userAccountRegister")
public class UserAccountRegisterController {

    @Resource
    private IUserAccountRegisterService service;

    /**
     * 根据用户密码注册
     * 一般不开放
     */
    @RequestMapping("/registerByUsernameAndPassword")
    public RestResult<Object> registerByUsernameAndPassword(
            @RequestParam("username") String username,
            @RequestParam("password") String password) {
        return RestResult.success(service.registerByUsernameAndPassword(username, password),
                CommonSuccessStateCodeAndMsg.REGISTER_SUCCESS);
    }

    /**
     * 发送注册验证码
     * @param dto 发送验证码的DTO
     * @return void
     */
    @RequestMapping("/sendRegisterVerificationCode")
    public RestResult<Void> sendRegisterVerificationCode(@RequestBody UserAccountSendVerificationCodeDTO dto) {
        service.sendRegisterVerificationCode(dto);
        return RestResult.success(null,
                CommonSuccessStateCodeAndMsg.SEND_VERIFICATION_CODE_SUCCESS);
    }

    /**
     * 根据手机号和验证码注册
     * @param dto 手机号、验证码、密码
     */
    @RequestMapping("/registerByPhoneAndVerificationCode")
    public RestResult<Object> registerByPhoneAndVerificationCode(@RequestBody UserAccountRegisterDTO dto) {
        return RestResult.success(service.registerByPhoneAndVerificationCode(dto),
                CommonSuccessStateCodeAndMsg.REGISTER_SUCCESS);
    }

    /**
     * 根据邮箱和验证码注册
     * @param dto 邮箱、验证码、密码
     * @return void
     */
    @RequestMapping("/registerByEmailAndVerificationCode")
    public RestResult<Object> registerByEmailAndVerificationCode(@RequestBody UserAccountRegisterDTO dto) {
        return RestResult.success(service.registerByEmailAndVerificationCode(dto),
                CommonSuccessStateCodeAndMsg.REGISTER_SUCCESS);
    }


}
